<template>
  <div>
    <el-row>
      <el-col :span="24" class="addRole">
        <!-- 查询 -->
        <el-popover placement="bottom-start" width="1000" style="margin-right:10px;" trigger="click">
          <el-form :inline="true" :model="search">
              <el-form-item label="图纸编号" >
                  <el-input v-model="search.drawCode"></el-input>
              </el-form-item>
              <el-form-item label="生产令号" >
                  <el-input v-model="search.makeNo"></el-input>
              </el-form-item>
              <el-form-item label="自定义编码" >
                  <el-input v-model="search.code"></el-input>
              </el-form-item>
              <el-button type="primary" @click="searchBtn">确认</el-button>
          </el-form>
          <el-button slot="reference" type="primary" icon="el-icon-search">查询</el-button>
        </el-popover>
      </el-col>
    </el-row>
    <!-- 29所列表 -->
    <tableList29 ref="tableList29" :postData="postData">
      <template v-slot:default="scope" >
        <el-button @click="showDialog('update',scope.row)" type="text" size="small">详情</el-button>
        <el-button @click="confirmHandle(scope.row)" type="text" size="small" v-if="scope.row.isFinishDelivery!==1">完成发货</el-button>
      </template>
    </tableList29>
    <!-- 计划任务详情 -->
    <el-dialog class="bodyNopaddingTop" :title="dialog.title" :visible.sync="dialog.isShow"  v-dialogDrag width="1100px" @opened="dialogOpened">
      <el-tabs v-model="dialog.activeName" @tab-click="dialogHandleClick">
        <el-tab-pane label="详情" name="1">
            <taskDetail29 :detailObj="dialog.formData" :type="dialog.type" :editDisalbe="true"></taskDetail29>
        </el-tab-pane>

        <el-tab-pane label="工艺编制" name="6" v-if="dialog.title==='计划详情'">
          <!-- <el-button type="primary" @click="showDialog2('insert')">新增</el-button> -->
          <processPlanList ref="processPlanListRef" :drawCode="dialog.drawCode" >
            <template v-slot:default="scope" >
              <!-- <el-button @click="showDialog2('update',scope.row)" type="text" size="small">详情</el-button> -->
              <el-button @click="showProgramDialog(scope.row)" type="text" size="small">编制程序</el-button>
            </template>
          </processPlanList>
        </el-tab-pane>

        <el-tab-pane label="29所工艺" name="2" v-if="dialog.title==='计划详情'">
          <processPlanList29 :data="dialog.formData" ref="processPlanList29Ref">
              <template v-slot:default="scope">
                <el-button @click="showDialog1('update',scope.row)" type="text" size="small">详情</el-button>
              </template>
          </processPlanList29>
        </el-tab-pane>
        <el-tab-pane label="图纸上传" name="3" v-if="dialog.title==='计划详情'">
          <uploadList :upLoadType="1" :drawNo="dialog.drawCode"  ref="drawing"></uploadList>
        </el-tab-pane>
        <el-tab-pane label="工艺上传" name="4" v-if="dialog.title==='计划详情'">
           <uploadList :upLoadType="2" :drawNo="dialog.drawCode"  ref="technology"></uploadList>
        </el-tab-pane>
        <el-tab-pane label="图形文件上传" name="5" v-if="dialog.title==='计划详情'">
           <uploadList :upLoadType="3" :drawNo="dialog.drawCode"  ref="graphicsFile"></uploadList>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
    <!-- 新增编辑29所计划任务详情 -->
    <el-dialog class="bodyNopaddingTop" :title="dialog1.title" :visible.sync="dialog1.isShow" v-dialogDrag>
       <processPlanDetail29 :formData="dialog1.formData" :type="dialog1.type" :tid="dialog.formData.tid" :disabled='true'></processPlanDetail29>
    </el-dialog>

    <!-- 新增/编辑工艺编制 -->
    <el-dialog class="bodyNopaddingTop" :title="dialog2.title" :visible.sync="dialog2.isShow" v-dialogDrag>
      <processPlanDetail :drawCode="dialog.drawCode" :detail="dialog2.formData" :type="dialog2.type" @editSuccess="editSuccess"></processPlanDetail>
    </el-dialog>
    <!-- 编程列表 -->
     <el-dialog class="bodyNopaddingTop" :title="programDialog.title" :visible.sync="programDialog.isShow" v-dialogDrag @opened="openedProgramDialog">
       <programList :programObj ="programDialog.programObj" ref="programDetail" ></programList>
    </el-dialog>
  </div>
</template>
<script>
import pdf from 'vue-pdf';
import planApi from 'plugins/axios/planApi.js';
import baseApi from 'plugins/axios/baseApi.js';
import materielApi from 'plugins/axios/materielApi.js';
import uploadList from 'views/components/uploadList.vue' /**1-图纸上传、2-工艺上传、3-图形文件上传 的列表组件 */
import tableList29 from 'views/components/tableList29.vue' /**29所列表组件 */
import taskDetail29 from 'views/components/taskDetail29.vue' /**29所任务详情组件 */
import processPlanList29 from 'views/components/processPlanList29.vue' /**29所工序列表组件 */
import processPlanDetail29 from 'views/components/processPlanDetail29.vue' /**29所工序详情组件 */
import processPlanList from 'views/components/processPlanList.vue' /**工艺编制列表组件 */
import processPlanDetail from 'views/components/processPlanDetail.vue' /**新增编辑工艺编制组件 */
import programList from 'views/components/programList.vue' /**编程详情组件 */

export default {
  components: {
    pdf,
    uploadList,
    tableList29,
    taskDetail29,
    processPlanList29,
    processPlanDetail29,
    processPlanList,
    processPlanDetail,
    programList
  },
  data(){
    return {
      status:'0',
      postData:{
        isUploadDraw:1,
        isMaterialArrvie:1,
        isMaterialTailor:1,
        isFinishProcess:1,
        isFinishProgram:1
      },
      machineAllList:[],/**所有机器列表 */
      search:{
        drawCode:"",
        makeNo:"",
        code:""
      },
      dialog:{/**弹框配置 */
        title:'',
        isShow:false,
        type:'',
        formData:{},
        activeName:'2',
        otherUpDataData:{},
        tableData:[],
        drawCode:''
      },
      dialog1:{
        title:'',
        isShow:false,
        formData:{},
        rules:{}
      },
      programDialog:{/**程序列表 */
        tid:'',
        title:'',
        isShow:false,
      },
      dialog2:{
        type:'',
        title:'',
        isShow:false,
        formData:{}
      }
    }
  },
  mounted(){
    this.status = this.$route.query.status;
    this.getTablList();
  },
  created(){
    
  },
  watch: {
    $route(){
      this.status = this.$route.query.status;
      this.search.drawCode="";
      this.search.makeNo="";
      this.search.code="";
      
      this.getTablList();
    }
  },
  methods:{

    getTablList(){/**计划列表 */
      let self = this;
      self.postData.drawCode=self.search.drawCode;
      self.postData.makeNo=self.search.makeNo;
      self.postData.code=self.search.code;
      self.postData.isFinishDelivery= self.status;
      self.$refs.tableList29.get29TableList()
    },
    searchBtn(){
      this.getTablList();
    },
    showDialog(type,row){
      this.dialog.activeName='6';
      this.dialog.type = type;
      switch(type){
        case 'insert':
          this.dialog.isShow=true;
          this.dialog.formData={};
          this.dialog.title = '新增计划任务';
          break;
        case 'update':
          this.dialog.isShow=true;
          this.dialog.formData = row;
          this.dialog.title = '计划详情';
          this.dialog.drawCode = row.drawCode;
          this.dialog.otherUpDataData.drawNo=row.drawCode;
          break;
        case 'print':
           this.dialog.formData = row;
           this.$refs.print1.getCgPdfData(row.id);
          break;
      } 
    },
    showDialog1(type,row){
      this.dialog1.isShow=true;
      this.dialog1.type=type;
      switch(type){
        case 'insert':
          this.dialog1.formData={};
          this.dialog1.title = '新增29所工艺详情';
          break;
        case 'update':
          this.dialog1.formData = row;
          this.dialog1.title = '编辑29所工艺详情';
        break;
      }
    },
    // showDialog2(type,row){
    //   this.dialog2.isShow=true;
    //   this.dialog2.type = type;
    //   switch(type){
    //     case 'insert':
    //       this.dialog2.formData={};
    //       this.dialog2.title ="新增工艺编制"
    //       break;
    //     case 'update':
    //       this.dialog2.formData=row;
    //       this.dialog2.title ="编辑工艺编制";
    //       break;
    //   }
    // },
    /**详情切换tab*/ 
    dialogHandleClick(){
      let self = this;
      switch(self.dialog.activeName){
        case '2':
          self.$refs.processPlanList29Ref.getProcessPlanList();
          break;
        case '3':
          self.$refs.drawing.getTableList();
          break;
        case '4':
          self.$refs.technology.getTableList();
          break;
        case '5':
          self.$refs.graphicsFile.getTableList();
          break;
        case '6':
          self.$refs.processPlanListRef.getProcessPlanList();
          break;
      }
    },
    /***确认编程完成 */
    confirmHandle(row){
      let self  = this;
      self.$confirm('是否确认编程完成?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          materielApi.finishProgram(row.id).then(res=>{
            self.$message.success("确认成功")
            self.getTablList();
          })
        }).catch(()=>{})
    },
    editSuccess(){
      this.dialog2.isShow=false;
      this.$refs.processPlanListRef.getProcessPlanList();
      this.$message.success(`${this.dialog2.title}成功`)
    },
    dialogOpened(){
      this.dialog.type==='update'? this.$refs.processPlanListRef.getProcessPlanList():'';
    },
    /**显示编程页面列表*/ 
    showProgramDialog(row){
      let self= this;
      self.programDialog.isShow = true;
      self.programDialog.title =`${row.nameName}详情`;
      self.programDialog.programObj = {
        data:row,
        tid:row.id,
        drawCode:row.drawNo,
        processId:row.name
      };
    },
    openedProgramDialog(){
      this.$refs.programDetail.getProgramList();
    }
  }
}
</script>
<style lang="stylus" scoped>
  .addRole
    padding-bottom 10px
  .content-rowspan div
    padding-left: 13px;
    line-height: 46px;
    border-bottom: 1px solid #ECEDEE;
    &:last-child
      border-bottom:none
</style>
